﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace reactiveBT.Time
{
    public class TimeManager
    {
        private static TimeManager instance = null;
        public static TimeManager Instance
        {
            get
            {
                if (instance == null)
                    instance = new TimeManager();
                return instance;
            }
        }
        //C#计时器类
        private Stopwatch watch;
        //
        private float prevTime;
        private float deltaTime;
        //每次调用返回距离上次调用的间隔时间
        public float DeltaTime
        {
            get
            {
                deltaTime = watch.ElapsedMilliseconds / 1000f - prevTime;
                prevTime = watch.ElapsedMilliseconds / 1000f;
                return deltaTime;
            }
        }
        TimeManager()
        {
            watch = Stopwatch.StartNew();
            prevTime = watch.ElapsedMilliseconds / 1000f;
        }
    }
}
